//
//  BaseNavViewController.swift
//  Weibo
//
//  Created by 冯童童 on 16/1/20.
//  Copyright © 2016年 冯童童. All rights reserved.
//

import UIKit

class BaseNavViewController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self

        // Do any additional setup after loading the view.
    }

    override func pushViewController(viewController: UIViewController, animated: Bool) {
        if childViewControllers.count != 0  {
            
            viewController.hidesBottomBarWhenPushed = true
            let btn = UIButton(title: "返回", fontSize: 14, color: UIColor.darkGrayColor(), backImageName: nil, imageName: "navigationbar_back_withtext")
            btn.addTarget(self, action: "back", forControlEvents: .TouchUpInside)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
            btn.sizeToFit()

        }
        super.pushViewController(viewController, animated: animated)
        
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        print("ok")
        
        return childViewControllers.count > 1
    }

    @objc private func back() {
       popViewControllerAnimated(true)
    }

    
    
}
